{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "fifty-alberta",
   "metadata": {},
   "source": [
    "# 逻辑回归"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "psychological-bunch",
   "metadata": {},
   "outputs": [],
   "source": [
    "##keep\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "homeless-welsh",
   "metadata": {},
   "source": [
    "## 加载iris数据集\n",
    "只取sepal length, sepal width作为训练数据。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "progressive-distributor",
   "metadata": {},
   "outputs": [],
   "source": [
    "##keep\n",
    "from sklearn import datasets\n",
    "X, y = datasets.load_iris(return_X_y = True)\n",
    "X = X[:, :2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "legal-liberty",
   "metadata": {},
   "source": [
    "各个属性：\n",
    "* sepal length in cm\n",
    "* sepal width in cm\n",
    "* petal length in cm\n",
    "* petal width in cm\n",
    "\n",
    "target:\n",
    "* Iris-Setosa\n",
    "* Iris-Versicolour\n",
    "* Iris-Virginica"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "38fbd785",
   "metadata": {},
   "source": [
    "打印X与y的形状："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "legendary-learning",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "friendly-circumstances",
   "metadata": {},
   "source": [
    "## 分割训练集与测试集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dressed-execution",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "secondary-penny",
   "metadata": {},
   "source": [
    "## 构建LogisticRegression模型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "catholic-sitting",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "duplicate-bunch",
   "metadata": {},
   "source": [
    "## 适配训练集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "advance-fairy",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "altered-scope",
   "metadata": {},
   "source": [
    "## 对测试集数据进行预测"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "wireless-announcement",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "buried-board",
   "metadata": {},
   "source": [
    "## 查看预测的准确率"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "serial-seeking",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "alike-latin",
   "metadata": {},
   "source": [
    "## 检查混淆矩阵"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "minimal-terrain",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "saved-table",
   "metadata": {},
   "source": [
    "## 检查模型预测的概率"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "quality-jewel",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "lovely-worcester",
   "metadata": {},
   "source": [
    "## 查看各个类别预测概率的直方图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "scientific-intervention",
   "metadata": {},
   "outputs": [],
   "source": [
    "##keep\n",
    "plt.figure(figsize = (12, 7))\n",
    "ax0 = plt.subplot(311, title = 'class 0')\n",
    "ax0.hist(y_pred_proba[:, 0], bins = 20)\n",
    "ax1 = plt.subplot(312, title = 'class 1', sharex = ax0)\n",
    "ax1.hist(y_pred_proba[:, 1], bins = 20)\n",
    "ax2 = plt.subplot(313, title = 'class 2', sharex = ax0)\n",
    "ax2.hist(y_pred_proba[:, 2], bins = 20)\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
